package com.ruoyi.report_gc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.ComputeReportResult;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import com.ruoyi.syrw.annotation.FIllBasicInfoForTaiZhang;
import com.ruoyi.report_tg.domain.TgsybgBaDetail;
import com.ruoyi.report_tg.domain.vo.TgsybgBaDetailVo;
import com.ruoyi.report_tg.mapper.TgsybgBaDetailMapper;
import com.ruoyi.sycs.service.IBiQualificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_gc.domain.bo.GcjxljjtbgBsInfoBo;
import com.ruoyi.report_gc.domain.vo.GcjxljjtbgBsInfoVo;
import com.ruoyi.report_gc.domain.GcjxljjtbgBsInfo;
import com.ruoyi.report_gc.mapper.GcjxljjtbgBsInfoMapper;
import com.ruoyi.report_gc.service.IGcjxljjtbgBsInfoService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 钢材机械连接接头试验检测报告Service业务层处理
 *
 * @author llb
 * @date 2024-06-18
 */
@RequiredArgsConstructor
@Service
public class GcjxljjtbgBsInfoServiceImpl implements IGcjxljjtbgBsInfoService {

    private final GcjxljjtbgBsInfoMapper baseMapper;
    private final TgsybgBaDetailMapper detailMapper;

    private final IBiQualificationService biQualificationService;

    private static final Long[] keys = {106L, 106L, 106L, 106L, 106L, 106L, 106L, 106L, 106L};

    /**
     * 查询钢材机械连接接头试验检测报告
     */
    @Override
    @FIllBasicInfo
    public GcjxljjtbgBsInfoVo queryById(Long excelId){
        GcjxljjtbgBsInfoVo gcjxljjtbgBsInfoVo = baseMapper.selectVoById(excelId);
        // 查询detail
        List<TgsybgBaDetailVo> baDetailVos = detailMapper.selectVoList(new LambdaQueryWrapper<TgsybgBaDetail>()
            .eq(TgsybgBaDetail::getExcelId, excelId));
        baDetailVos.forEach(v->{
            v.setQualInfo(biQualificationService.queryById(v.getQualId()));
        });
        // 格式化 技术指标
        biQualificationService.compute(baDetailVos);
        gcjxljjtbgBsInfoVo.setBaDetailVos(baDetailVos);
        return gcjxljjtbgBsInfoVo;
    }

    @Override
    @FIllBasicInfoForTaiZhang
    public GcjxljjtbgBsInfoVo queryByIdForTaizhang(Long excelId) {
        GcjxljjtbgBsInfoVo gcjxljjtbgBsInfoVo = baseMapper.selectVoById(excelId);
        // 查询detail
        List<TgsybgBaDetailVo> baDetailVos = detailMapper.selectVoList(new LambdaQueryWrapper<TgsybgBaDetail>()
            .eq(TgsybgBaDetail::getExcelId, excelId));
        baDetailVos.forEach(v->{
            v.setQualInfo(biQualificationService.queryById(v.getQualId()));
        });
        // 格式化 技术指标
        biQualificationService.compute(baDetailVos);
        gcjxljjtbgBsInfoVo.setBaDetailVos(baDetailVos);

        //连接件抗拉强度实测值(MPa)台账
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz1())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdscz1());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz2())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz2());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz3())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz3());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz4())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz4());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz5())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz5());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz6())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz6());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz7())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz7());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz8())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz8());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdscz9())){
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()+"/"+gcjxljjtbgBsInfoVo.getQiangdscz9());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang()) && gcjxljjtbgBsInfoVo.getQiangdsczTaizhang().endsWith("/")) {
            gcjxljjtbgBsInfoVo.setQiangdsczTaizhang(gcjxljjtbgBsInfoVo.getQiangdsczTaizhang().substring(0, gcjxljjtbgBsInfoVo.getQiangdsczTaizhang().length() - 1));
        }

        //断裂特征台账
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz1())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDaunltz1());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz2())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz2());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz3())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz3());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz4())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz4());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz5())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz5());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz6())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz6());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz7())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz7());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz8())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz8());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDaunltz9())){
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDaunltz9());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanltzTaizhang()) && gcjxljjtbgBsInfoVo.getDuanltzTaizhang().endsWith("/")) {
            gcjxljjtbgBsInfoVo.setDuanltzTaizhang(gcjxljjtbgBsInfoVo.getDuanltzTaizhang().substring(0, gcjxljjtbgBsInfoVo.getDuanltzTaizhang().length() - 1));
        }

        //断裂位置(mm)台账
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz1())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwz1());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz2())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz2());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz3())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz3());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz4())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz4());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz5())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz5());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz6())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz6());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz7())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz7());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz8())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz8());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwz9())){
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()+"/"+gcjxljjtbgBsInfoVo.getDuanlwz9());
        }
        if (ObjectUtils.isNotEmpty(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang()) && gcjxljjtbgBsInfoVo.getDuanlwzTaizhang().endsWith("/")) {
            gcjxljjtbgBsInfoVo.setDuanlwzTaizhang(gcjxljjtbgBsInfoVo.getDuanlwzTaizhang().substring(0, gcjxljjtbgBsInfoVo.getDuanlwzTaizhang().length() - 1));
        }
        return gcjxljjtbgBsInfoVo;
    }

    /**
     * 查询钢材机械连接接头试验检测报告列表
     */
    @Override
    public TableDataInfo<GcjxljjtbgBsInfoVo> queryPageList(GcjxljjtbgBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<GcjxljjtbgBsInfo> lqw = buildQueryWrapper(bo);
        Page<GcjxljjtbgBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询钢材机械连接接头试验检测报告列表
     */
    @Override
    public List<GcjxljjtbgBsInfoVo> queryList(GcjxljjtbgBsInfoBo bo) {
        LambdaQueryWrapper<GcjxljjtbgBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<GcjxljjtbgBsInfo> buildQueryWrapper(GcjxljjtbgBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<GcjxljjtbgBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, GcjxljjtbgBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, GcjxljjtbgBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), GcjxljjtbgBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaogbh()), GcjxljjtbgBsInfo::getBaogbh, bo.getBaogbh());
        lqw.eq(StringUtils.isNotBlank(bo.getShigwtdw()), GcjxljjtbgBsInfo::getShigwtdw, bo.getShigwtdw());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), GcjxljjtbgBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), GcjxljjtbgBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), GcjxljjtbgBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), GcjxljjtbgBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), GcjxljjtbgBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), GcjxljjtbgBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsj()), GcjxljjtbgBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), GcjxljjtbgBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), GcjxljjtbgBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), GcjxljjtbgBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getPih()), GcjxljjtbgBsInfo::getPih, bo.getPih());
        lqw.eq(StringUtils.isNotBlank(bo.getGangjqddjph()), GcjxljjtbgBsInfo::getGangjqddjph, bo.getGangjqddjph());
        lqw.eq(StringUtils.isNotBlank(bo.getLianjxs()), GcjxljjtbgBsInfo::getLianjxs, bo.getLianjxs());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh1()), GcjxljjtbgBsInfo::getShijbh1, bo.getShijbh1());
        lqw.eq(StringUtils.isNotBlank(bo.getZhij1()), GcjxljjtbgBsInfo::getZhij1, bo.getZhij1());
        lqw.eq(StringUtils.isNotBlank(bo.getJiemj1()), GcjxljjtbgBsInfo::getJiemj1, bo.getJiemj1());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb1()), GcjxljjtbgBsInfo::getJiszb1, bo.getJiszb1());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz1()), GcjxljjtbgBsInfo::getQiangdscz1, bo.getQiangdscz1());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz1()), GcjxljjtbgBsInfo::getDaunltz1, bo.getDaunltz1());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz1()), GcjxljjtbgBsInfo::getDuanlwz1, bo.getDuanlwz1());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd1()), GcjxljjtbgBsInfo::getJiegpd1, bo.getJiegpd1());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh2()), GcjxljjtbgBsInfo::getShijbh2, bo.getShijbh2());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb2()), GcjxljjtbgBsInfo::getJiszb2, bo.getJiszb2());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz2()), GcjxljjtbgBsInfo::getQiangdscz2, bo.getQiangdscz2());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz2()), GcjxljjtbgBsInfo::getDaunltz2, bo.getDaunltz2());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz2()), GcjxljjtbgBsInfo::getDuanlwz2, bo.getDuanlwz2());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd2()), GcjxljjtbgBsInfo::getJiegpd2, bo.getJiegpd2());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh3()), GcjxljjtbgBsInfo::getShijbh3, bo.getShijbh3());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb3()), GcjxljjtbgBsInfo::getJiszb3, bo.getJiszb3());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz3()), GcjxljjtbgBsInfo::getQiangdscz3, bo.getQiangdscz3());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz3()), GcjxljjtbgBsInfo::getDaunltz3, bo.getDaunltz3());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz3()), GcjxljjtbgBsInfo::getDuanlwz3, bo.getDuanlwz3());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd3()), GcjxljjtbgBsInfo::getJiegpd3, bo.getJiegpd3());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh4()), GcjxljjtbgBsInfo::getShijbh4, bo.getShijbh4());
        lqw.eq(StringUtils.isNotBlank(bo.getZhij4()), GcjxljjtbgBsInfo::getZhij4, bo.getZhij4());
        lqw.eq(StringUtils.isNotBlank(bo.getJiemj4()), GcjxljjtbgBsInfo::getJiemj4, bo.getJiemj4());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb4()), GcjxljjtbgBsInfo::getJiszb4, bo.getJiszb4());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz4()), GcjxljjtbgBsInfo::getQiangdscz4, bo.getQiangdscz4());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz4()), GcjxljjtbgBsInfo::getDaunltz4, bo.getDaunltz4());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz4()), GcjxljjtbgBsInfo::getDuanlwz4, bo.getDuanlwz4());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd4()), GcjxljjtbgBsInfo::getJiegpd4, bo.getJiegpd4());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh5()), GcjxljjtbgBsInfo::getShijbh5, bo.getShijbh5());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb5()), GcjxljjtbgBsInfo::getJiszb5, bo.getJiszb5());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz5()), GcjxljjtbgBsInfo::getQiangdscz5, bo.getQiangdscz5());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz5()), GcjxljjtbgBsInfo::getDaunltz5, bo.getDaunltz5());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz5()), GcjxljjtbgBsInfo::getDuanlwz5, bo.getDuanlwz5());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd5()), GcjxljjtbgBsInfo::getJiegpd5, bo.getJiegpd5());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh6()), GcjxljjtbgBsInfo::getShijbh6, bo.getShijbh6());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb6()), GcjxljjtbgBsInfo::getJiszb6, bo.getJiszb6());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz6()), GcjxljjtbgBsInfo::getQiangdscz6, bo.getQiangdscz6());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz6()), GcjxljjtbgBsInfo::getDaunltz6, bo.getDaunltz6());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz6()), GcjxljjtbgBsInfo::getDuanlwz6, bo.getDuanlwz6());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd6()), GcjxljjtbgBsInfo::getJiegpd6, bo.getJiegpd6());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh7()), GcjxljjtbgBsInfo::getShijbh7, bo.getShijbh7());
        lqw.eq(StringUtils.isNotBlank(bo.getZhij7()), GcjxljjtbgBsInfo::getZhij7, bo.getZhij7());
        lqw.eq(StringUtils.isNotBlank(bo.getJiemj7()), GcjxljjtbgBsInfo::getJiemj7, bo.getJiemj7());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb7()), GcjxljjtbgBsInfo::getJiszb7, bo.getJiszb7());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz7()), GcjxljjtbgBsInfo::getQiangdscz7, bo.getQiangdscz7());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz7()), GcjxljjtbgBsInfo::getDaunltz7, bo.getDaunltz7());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz7()), GcjxljjtbgBsInfo::getDuanlwz7, bo.getDuanlwz7());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd7()), GcjxljjtbgBsInfo::getJiegpd7, bo.getJiegpd7());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh8()), GcjxljjtbgBsInfo::getShijbh8, bo.getShijbh8());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb8()), GcjxljjtbgBsInfo::getJiszb8, bo.getJiszb8());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz8()), GcjxljjtbgBsInfo::getQiangdscz8, bo.getQiangdscz8());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz8()), GcjxljjtbgBsInfo::getDaunltz8, bo.getDaunltz8());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz8()), GcjxljjtbgBsInfo::getDuanlwz8, bo.getDuanlwz8());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd8()), GcjxljjtbgBsInfo::getJiegpd8, bo.getJiegpd8());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh9()), GcjxljjtbgBsInfo::getShijbh9, bo.getShijbh9());
        lqw.eq(StringUtils.isNotBlank(bo.getJiszb9()), GcjxljjtbgBsInfo::getJiszb9, bo.getJiszb9());
        lqw.eq(StringUtils.isNotBlank(bo.getQiangdscz9()), GcjxljjtbgBsInfo::getQiangdscz9, bo.getQiangdscz9());
        lqw.eq(StringUtils.isNotBlank(bo.getDaunltz9()), GcjxljjtbgBsInfo::getDaunltz9, bo.getDaunltz9());
        lqw.eq(StringUtils.isNotBlank(bo.getDuanlwz9()), GcjxljjtbgBsInfo::getDuanlwz9, bo.getDuanlwz9());
        lqw.eq(StringUtils.isNotBlank(bo.getJiegpd9()), GcjxljjtbgBsInfo::getJiegpd9, bo.getJiegpd9());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancjl()), GcjxljjtbgBsInfo::getJiancjl, bo.getJiancjl());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), GcjxljjtbgBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), GcjxljjtbgBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getBgFlag()), GcjxljjtbgBsInfo::getBgFlag, bo.getBgFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getJianc()), GcjxljjtbgBsInfo::getJianc, bo.getJianc());
        lqw.eq(StringUtils.isNotBlank(bo.getJil()), GcjxljjtbgBsInfo::getJil, bo.getJil());
        lqw.eq(StringUtils.isNotBlank(bo.getFuh()), GcjxljjtbgBsInfo::getFuh, bo.getFuh());
        lqw.eq(StringUtils.isNotBlank(bo.getRiq()), GcjxljjtbgBsInfo::getRiq, bo.getRiq());
        return lqw;
    }

    /**
     * 新增钢材机械连接接头试验检测报告
     */
    @Override
    @DSTransactional
    public Boolean insertByBo(GcjxljjtbgBsInfoBo bo) {
        GcjxljjtbgBsInfo add = BeanUtil.toBean(bo, GcjxljjtbgBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
            // 新增详细 多个keys
            ArrayList<TgsybgBaDetail> details = new ArrayList<>(9);
            for (Long key : keys) {
                details.add(new TgsybgBaDetail(add.getExcelId(), key));
            }
            detailMapper.insertBatch(details);
        }
        return flag;
    }

    /**
     * 修改钢材机械连接接头试验检测报告
     */
    @Override
    @DSTransactional
    @ComputeReportResult
    public Boolean updateByBo(GcjxljjtbgBsInfoBo bo) {
        // 增加对 是否合格 的填充
        fillExcelResult(bo);
        GcjxljjtbgBsInfo update = BeanUtil.toBean(bo, GcjxljjtbgBsInfo.class);
        validEntityBeforeSave(update);
        boolean flag = baseMapper.updateById(update) > 0;
        if (flag) {
            detailMapper.updateBatchById(BeanUtil.copyToList(bo.getBaDetailVos(), TgsybgBaDetail.class));
        }
        return flag;
    }


    private void fillExcelResult(GcjxljjtbgBsInfoBo bo) {
        if (CollUtil.isNotEmpty(bo.getBaDetailVos())) {
            for (TgsybgBaDetailVo detailVo : bo.getBaDetailVos()) {
                if ("不符合".equals(detailVo.getJiegpd())) {
                    bo.setExcelResult(2);
                    return;
                }
            }
            bo.setExcelResult(1);
        }
        bo.setExcelResult(0);
    }

    public boolean isWell(Long excelId) {
        return baseMapper.selectVoById(excelId).getExcelResult() != 2;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(GcjxljjtbgBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除钢材机械连接接头试验检测报告
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public GcjxljjtbgBsInfoVo jcjl(GcjxljjtbgBsInfoVo vo) {
        StringBuilder result = new StringBuilder("检测结论：依据《钢筋机械连接技术规程》(JGJ 107-2016)检测，该批钢筋机械连接件所检指标符合《钢筋机械连接技术规程》(JGJ 107-2016)中I级接头技术要求，可用于桥涵工程。");
        vo.setJiancjl(result.toString());
        return vo;
    }
}
